package leets.leet2335;

public class Solution {
    public int fillCups(int[] amount) {
        int res=0;
        while (true){
            int max_index=0;
            int second_index=0;
            if (amount[0]>amount[1]) {
                if (amount[0]>amount[2]){
                    second_index=amount[1]>amount[2]?1:2;
                }else {
                    max_index=2;
                }
            }else {
                if (amount[1]>amount[2]){
                    max_index=1;
                    second_index=amount[0]>amount[2]?0:2;
                }else {
                    max_index=2;
                    second_index=1;
                }
            }
            if (amount[max_index]==0){
                return res;
            }
            amount[max_index]--;
            if (amount[second_index]>0){
                amount[second_index]--;
            }
            res++;

        }
    }
}